package com.example.chapter0404;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ToggleButton tb = findViewById(R.id.toggleButton);
        Switch sw1 = findViewById(R.id.switch1);
        Switch sw2 = findViewById(R.id.switch2);
        tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    Toast.makeText(MainActivity.this,"ToggleButton 的事件  开启",Toast.LENGTH_LONG).show();
                }else {
                    Toast.makeText(MainActivity.this,"ToggleButton 的事件  关闭",Toast.LENGTH_LONG).show();
                }

            }
        });
        sw1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Toast.makeText(MainActivity.this,"Switch 1 的事件",Toast.LENGTH_SHORT).show();
            }
        });
        sw2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Toast.makeText(MainActivity.this,"Switch 2 的事件",Toast.LENGTH_SHORT).show();
            }
        });
    }
}